from tornado.web import RequestHandler

from sqlalchemy import Column, Integer, String

from core.base_model import BaseModel

class Customer(BaseModel):
    __tablename__ = 'customer'  # 表名
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(50))
    age = Column(Integer)
    sex = Column(String(10))

    @classmethod
    def get_customers_by_sex(cls,_sex):
        """
        查询不同性别的顾客的名称
        """
        customers = cls.db().query(cls.name).filter(cls.sex == _sex).all()
        return customers.json


class MainHandler(RequestHandler):
    def get(self):
        customers = Customer.get_customers_by_sex("男")
        self.write(f"Hello, world{customers}")